//
//  TYTabBarController.m
//  
//
//  Created by 黄卫 on 17/2/24.
//  Copyright © 2017年 huangwei. All rights reserved.
//

#import "TYTabBarController.h"
#import "TYCustomNavgationCotr.h"
#import "HomeVC.h"
#import "MineVC.h"
#import "MessageVC.h"
#import "HealthRecordVC.h"
#import "TYGlobalManager.h"


@interface TYTabBarController ()

@end

@implementation TYTabBarController

- (void)dealloc
{
    NSLog(@"%s",__func__);
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.tabBar setBackgroundImage:imageWithColor(WhiteColor)];
    [self.tabBar setClipsToBounds:YES];
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width, 0.5)];
    line.backgroundColor = RGB(229, 229, 229);
    [self.tabBar addSubview:line];
    
    //初始化tabBar控制器
    [self initTabBarVCS];
}


- (void)initTabBarVCS
{
    //home
    HomeVC *homeVc = [[HomeVC alloc] init];
    TYCustomNavgationCotr *homeNav = [[TYCustomNavgationCotr alloc] initWithRootViewController:homeVc];
    homeNav.tabBarItem = [self createTabBarItemWithTitle:@"首页" imageName:@"icon_home1" selectedImage:@"icon_home1"];
//    cashieVC.title = [GJGlobalManager shareInstance].currentShopInfo.shop.shopName?:@"我的店铺";

    //healthy record
    HealthRecordVC *healthRVc = [[HealthRecordVC alloc] init];
    TYCustomNavgationCotr *healtyRNav = [[TYCustomNavgationCotr alloc] initWithRootViewController:healthRVc];
    healtyRNav.tabBarItem = [self createTabBarItemWithTitle:@"健康档案" imageName:@"icon_home1" selectedImage:@"icon_home1"];
    
    //message
    MessageVC *msgVc = [[MessageVC alloc] init];
    TYCustomNavgationCotr *msgNav = [[TYCustomNavgationCotr alloc] initWithRootViewController:msgVc];
    msgNav.tabBarItem = [self createTabBarItemWithTitle:@"消息" imageName:@"icon_home1" selectedImage:@"icon_home1"];
    
    MineVC *mineVc = [[MineVC alloc] init];
    TYCustomNavgationCotr *mineNav = [[TYCustomNavgationCotr alloc] initWithRootViewController:mineVc];
    mineNav.tabBarItem = [self createTabBarItemWithTitle:@"我的" imageName:@"icon_home1" selectedImage:@"icon_home1"];
    [self setViewControllers:@[homeNav,healtyRNav,msgNav,mineNav] animated:NO];
}


/**
 * 创建UITabBarItem
 */
- (UITabBarItem *)createTabBarItemWithTitle:(NSString *)title imageName:(NSString *)imageName selectedImage:(NSString *)selectedImageName
{
    UIImage *norImage = [ImageNamed(imageName) imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *serImage = [ImageNamed(selectedImageName) imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:title image:norImage selectedImage:serImage];
    item.titlePositionAdjustment = UIOffsetMake(0, -3);
    [item setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:UIColorFromRGB(0x282828), NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
    [item setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:Color_Main, NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
    return item;
}

@end
